package com.lwj.service.impl;

import com.lwj.constant.ConstantDefinition;
import com.lwj.entity.User;
import com.lwj.mapper.UserDAO;
import com.lwj.service.RedisService;
import com.lwj.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Service("userService")
public class UserServiceImpl implements UserService {

    @Resource
    private UserDAO userDAO;

    @Resource
    private RedisService redisService;
    public User getUserById(User user) {
        User user1 = userDAO.selectByPrimaryKey(user.getId());
        redisService.saveStringValue(user1.getName(),"123",3000L);
        return user1;
    }

    public void insertUser(User user) {
        userDAO.insert(user);
    }

    public String login(String name, String password, HttpServletRequest request) {
        User user = userDAO.selectUser(name,password);
        if(user==null){
            return "err";
        }else {
            request.getSession().setAttribute(ConstantDefinition.SESSION_KEY_USERNAME,user);
            return "susscss";
        }

    }
}
